﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Lilium.RetailAudit.Data
{
	public sealed class MetaModelProvider
	{
		public MetaTable GetMetaTable(Type entityType)
		{
			if (entityType == null) throw new ArgumentNullException("entityType");

			var tableAttribute = (TableAttribute)entityType.GetCustomAttributes(typeof(TableAttribute), true).SingleOrDefault();
			if (tableAttribute != null)
				return new MetaTable(
					!string.IsNullOrEmpty(tableAttribute.Name) ? tableAttribute.Name : entityType.Name,
					tableAttribute.DefaultSortExpression);
			else
				return new MetaTable(entityType.Name, null);
		}
	}
}
